﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class admin_ChangePwd : System.Web.UI.Page
{
    db_teacher teach = new db_teacher();
    protected void Page_Load(object sender, EventArgs e)
    {
        
        Server.Execute("checkTeach.aspx");// 此处用户权限验证
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string pwd = Tools.mymd5(yPWD.Text);
        string teacherID = "";
        try
        {
            if (Session["teacherID"] == null)
            {
                Response.Redirect("../teacher/login.aspx");
            }
            else
            {
                teacherID = Session["teacherID"].ToString();
            }

        }
        catch
        {
            teacherID = null;
            Response.Write("<script language=javascript>alert('操作超时，请重新登录！');top.location.href='../teacher/login.aspx';</script>");
        }
        if (teach.checkPwd(teacherID, pwd))
        {
            if (xPWD2.Text.Trim().Length < 6 || xPWD2.Text.Trim().Length > 16)
            {
                Response.Write("<script language=javascript>alert('密码长度不符合要求！');</script>");
            }
            else
            {
                if (teach.setPwd(teacherID, Tools.mymd5(xPWD1.Text)))
                {
                    Session.Clear();
                    Response.Write("<script language=javascript>alert('修改密码成功！现在请重新登录。');top.location.href='../teacher/login.aspx';</script>");
                }
                else
                {
                    Response.Write("<script language=javascript>alert('修改失败！');</script>");
                }
            }
        }
        else
        {
            Response.Write("<script language=javascript>alert('原密码错误！');</script>");
        }
    }
}
